/*
 * ZhuaTu.java
 *
 * Created on __DATE__, __TIME__
 */

package com.gcb.swing.zhua;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

import com.gcb.apache.http.PicCollector;

/**
 * 
 * @author __USER__
 */
public class ZhuaTu extends javax.swing.JFrame implements ActionListener,
		ListSelectionListener {

	/** Creates new form ZhuaTu */
	public ZhuaTu() {
		initComponents();
		init();
	}

	/**
	 * This method is called from within the constructor to initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is always
	 * regenerated by the Form Editor.
	 */
	//GEN-BEGIN:initComponents
	// <editor-fold defaultstate="collapsed" desc="Generated Code">
	private void initComponents() {

		jTextField1 = new javax.swing.JTextField();
		jLabel1 = new javax.swing.JLabel();
		jRadioButton1 = new javax.swing.JRadioButton();
		jRadioButton2 = new javax.swing.JRadioButton();
		jButton1 = new javax.swing.JButton();
		jLabel2 = new javax.swing.JLabel();
		jButton2 = new javax.swing.JButton();

		setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

		jTextField1
				.setText("http://www.zhuoku.com/zhuomianbizhi/jingxuan-jingxuantaotu/20130204175806.htm");

		jLabel1.setText("\u4fdd\u5b58\u5230\uff1a");

		jRadioButton1.setSelected(true);
		jRadioButton1.setText("1366x768");
		jRadioButton1.setName("vga");

		jRadioButton2.setText("1440x900");
		jRadioButton2.setName("vga");

		jButton1.setText("\u5f00\u59cb\u6293\u56fe");

		jLabel2.setText("\u5206\u8fa8\u7387\uff1a");

		jButton2.setText("\u6e05\u7a7a");

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
				getContentPane());
		getContentPane().setLayout(layout);
		layout.setHorizontalGroup(layout
				.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(
						layout.createSequentialGroup()
								.addContainerGap()
								.addComponent(jLabel1)
								.addPreferredGap(
										javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.LEADING)
												.addComponent(
														jTextField1,
														javax.swing.GroupLayout.PREFERRED_SIZE,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														javax.swing.GroupLayout.PREFERRED_SIZE)
												.addGroup(
														javax.swing.GroupLayout.Alignment.TRAILING,
														layout.createSequentialGroup()
																.addGroup(
																		layout.createParallelGroup(
																				javax.swing.GroupLayout.Alignment.TRAILING)
																				.addGroup(
																						layout.createSequentialGroup()
																								.addGap(40,
																										40,
																										40)
																								.addComponent(
																										jLabel2)
																								.addGap(18,
																										18,
																										18)
																								.addComponent(
																										jRadioButton1)
																								.addPreferredGap(
																										javax.swing.LayoutStyle.ComponentPlacement.RELATED,
																										66,
																										Short.MAX_VALUE))
																				.addGroup(
																						layout.createSequentialGroup()
																								.addComponent(
																										jButton2,
																										javax.swing.GroupLayout.PREFERRED_SIZE,
																										67,
																										javax.swing.GroupLayout.PREFERRED_SIZE)
																								.addGap(48,
																										48,
																										48)))
																.addGroup(
																		layout.createParallelGroup(
																				javax.swing.GroupLayout.Alignment.LEADING)
																				.addComponent(
																						jRadioButton2)
																				.addComponent(
																						jButton1))
																.addGap(184,
																		184,
																		184)))));
		layout.setVerticalGroup(layout
				.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(
						layout.createSequentialGroup()
								.addGap(32, 32, 32)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.BASELINE)
												.addComponent(jLabel1)
												.addComponent(
														jTextField1,
														javax.swing.GroupLayout.PREFERRED_SIZE,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														javax.swing.GroupLayout.PREFERRED_SIZE))
								.addGap(29, 29, 29)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.BASELINE)
												.addComponent(jRadioButton2)
												.addComponent(jRadioButton1)
												.addComponent(jLabel2))
								.addGap(18, 18, 18)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.BASELINE)
												.addComponent(jButton1)
												.addComponent(jButton2))
								.addContainerGap(149, Short.MAX_VALUE)));

		pack();
	}// </editor-fold>
	//GEN-END:initComponents

	public void init() {
		jButton1.setActionCommand("zhua");
		jButton2.setActionCommand("clean");
		jButton1.addActionListener(this);
		jButton2.addActionListener(this);
	}

	/**
	 * @param args
	 *            the command line arguments
	 */
	public static void main(String args[]) {
		java.awt.EventQueue.invokeLater(new Runnable() {
			public void run() {
				new ZhuaTu().setVisible(true);
			}
		});
	}

	//GEN-BEGIN:variables
	// Variables declaration - do not modify
	private javax.swing.JButton jButton1;
	private javax.swing.JButton jButton2;
	private javax.swing.JLabel jLabel1;
	private javax.swing.JLabel jLabel2;
	private javax.swing.JRadioButton jRadioButton1;
	private javax.swing.JRadioButton jRadioButton2;
	private javax.swing.JTextField jTextField1;
	private PicCollector picZhua;

	// End of variables declaration//GEN-END:variables
	@Override
	public void valueChanged(ListSelectionEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		String command = e.getActionCommand();
		if ("zhua".equals(command)) {
			picZhua = new PicCollector();
			String vga;
			String path;
			if (jRadioButton1.isSelected()) {
				vga = jRadioButton1.getText();
				path = "F:\\快盘\\我的图片\\" + vga + "\\";
				String baseUrl = jTextField1.getText();
				picZhua.zhuoku(baseUrl, path, vga);
			}
			if (jRadioButton2.isSelected()) {
				vga = jRadioButton2.getText();
				path = "F:\\快盘\\我的图片\\" + vga + "\\";
				String baseUrl = jTextField1.getText();
				picZhua.zhuoku(baseUrl, path, vga);
			}
		}else if("clean".equals(command)){
			jTextField1.setText("");
		}
	}

}